<template>
  <svg aria-hidden="true" class="svg-icon" :class="className">
    <use :xlink:href="symbolId" :fill="color" />
  </svg>
</template>

<script setup>
/**
 * SVG 图标组件
 * @file SvgIcon/index.vue
 */

const props = defineProps({
  /**
   * 图标名称
   * @type {String}
   */
  name: {
    type: String,
    required: true
  },
  
  /**
   * 图标填充颜色
   * @type {String}
   */
  color: {
    type: String,
    default: ''
  },
  
  /**
   * 自定义类名
   * @type {String}
   */
  className: {
    type: String,
    default: ''
  }
})

/**
 * 图标的唯一标识符
 * @type {import('vue').ComputedRef<string>}
 */
const symbolId = computed(() => `#icon-${props.name}`)
</script>

<style lang="scss" scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  fill: currentColor;
  vertical-align: middle;
}
</style> 